﻿
@using IOA.MES.DataAccess.VModel
@{
    ViewBag.Title = "打包管理";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    var workshops = ViewBag.Workshops as List<VWorkshop>;
    var packStatuses = ViewBag.PackStatusEnum as List<KeyValuePair<int, string>>;
    var inspectStatuses = ViewBag.PackInspectStatusEnum as List<KeyValuePair<int, string>>;
}

@section Contents{
    <style>
        .layui-form-label {
            width: auto;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.WorkShop}}：</label>
                        <div class="layui-input-inline">
                            <select id="selWorkshops" lay-filter="selWorkshops">
                                <option value="">所有车间</option>
                                @foreach (var item in workshops)
                                {
                                    <option value="@item.WorkshopCode">@item.WorkshopName</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.OrderNo}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtOrderNo" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.WorkorderNo}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtWorkOrderNo" placeholder="请输入工单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.PackBatchNo}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtPackBatchNo" placeholder="请输入包装批次号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.PackNo}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtPackNo" placeholder="请输入包装编码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.PackTime}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtRangeDate" placeholder="请选择打包日期" value="@(DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd")+" 至 "+DateTime.Today.ToString("yyyy-MM-dd"))" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.PackStatus}}：</label>
                        <div class="layui-input-inline">
                            <select id="selPackStatus" lay-filter="selPackStatus">
                                <option value="-1">所有状态</option>
                                @foreach (var item in packStatuses)
                                {
                                    <option value="@item.Key">@item.Value</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.InboundInspectStatus}}：</label>
                        <div class="layui-input-inline">
                            <select id="selInspectStatus" lay-filter="selInspectStatus">
                                <option value="-1">所有状态</option>
                                @foreach (var item in inspectStatuses)
                                {
                                    <option value="@item.Key">@item.Value</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-list" type="button" onclick="newPack('');">
                            <i class="layui-icon layui-icon-addition layuiadmin-button-btn"></i>{{lang.Field.CreatePack}}
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>


@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);
        function initLayui() {
            layui.use(['table', 'layer', 'form', 'laydate'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form,
                    laydate = layui.laydate;
                laydate.render({
                    elem: '#txtRangeDate'
                    , range: '至'
                });
                var options = {
                    elem: '#table'
                    , url: '/WorkOrder/QueryPacks'
                    , method: "post"
                    , where: { workshopCode: "", orderNo: "", workOrderNo: "", packBatchNo: "", packNo: "", startDate: "@DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd")", endDate: "@DateTime.Today.ToString("yyyy-MM-dd")", packStatus: null, inspectStatus: null }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: '序号', type: "numbers", width: 80, fixed: 'left' }
                        , { field: 'PackNo', title: '包装编号', minWidth: 200, fixed: 'left' }
                        , { field: 'OrderNo', title: '订单号', minWidth: 200 }
                        , { field: 'WorkOrderNo', title: '工单号', minWidth: 220 }
                        , { field: 'IVPowerLevel', title: '功率档', minWidth: 100 }
                        , { field: 'IVCurrentLevel', title: '电流档', minWidth: 100 }
                        , { field: 'QLevel', title: '组件等级', minWidth: 100 }
                        , { field: 'ComponentColor', title: '组件颜色', minWidth: 100 }
                        , { field: 'NameplateModel', title: '铭牌方案', minWidth: 150 }
                        , { field: 'CNCreateBy', title: '打包人', minWidth: 100 }
                        , { field: 'CreateTimeStr', title: '打包时间', minWidth: 150 }
                        , { field: 'CNPackStatus', title: '打包状态', fixed: 'right', minWidth: 100 }
                        , { field: 'CNPackInspectStatus', title: '入库检状态', fixed: 'right', minWidth: 100 }
                        , {
                            title: '操作', fixed: 'right', width: 100, templet: function (d) {
                                var str = d.PackStatus == 2 ? '' : '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="editPack(\'' + d.PackNo + '\')"><i class="layui-icon">&#xe615;</i>查看</button>';
                                return str;
                            }
                        }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.page.curr = 1;
                    options.where.workshopCode = $("#selWorkshops").val().trim();
                    options.where.orderNo = $("#txtOrderNo").val();
                    options.where.workOrderNo = $("#txtWorkOrderNo").val();
                    options.where.packBatchNo = $("#txtPackBatchNo").val();
                    options.where.packNo = $("#txtPackNo").val();
                    options.where.packStatus = parseInt($("#selPackStatus").val()) == -1 ? null : parseInt($("#selPackStatus").val());
                    options.where.inspectStatus = parseInt($("#selInspectStatus").val()) == -1 ? null : parseInt($("#selInspectStatus").val());
                    var rangeTime = $("#txtRangeDate").val().trim() == '' ? new Array() : $("#txtRangeDate").val().trim().split(' 至 ');
                    options.where.startDate = rangeTime.length <= 0 ? null : rangeTime[0];
                    options.where.endDate = rangeTime.length <= 0 ? null : rangeTime[1];

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }
            });
        }

        function newPack() {
            parent.layui.index.openTabsPage("/WorkOrder/UnionPack", "新建打包");
        }
        function editPack(packNo) {
            parent.layui.index.openTabsPage("/WorkOrder/PackEdit?packNo=" + packNo, packNo == "" ? "新建打包" : "查看包装");
        }
    </script>
}
